package com.mall.orders.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.mall.commons.utils.CommonResult;
import com.mall.model.domain.OmsOrder;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.OmsOrderVO;
import com.mall.orders.service.OmsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单表(OmsOrder)表控制层
 *
 * @author wishmumu
 * @since 2023-03-11 15:42:49
 */
@RestController
@RequestMapping("order")
public class OmsOrderController {
    /**
     * 服务对象
     */
    @Autowired
    private OmsOrderService orderService;

    /**
     * 查询订单
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public CommonResult selectAll(Integer pageNum, Integer pageSize, @RequestParam(required = false) Integer sourceType, @RequestParam(required = false) Integer status,
                                  @RequestParam(required = false) String createTime, @RequestParam(required = false) String orderSn,
                                  @RequestParam(required = false) Integer orderType, @RequestParam(required = false) String receiverKeyword) {
        CommonPage page = orderService.selectAll(pageNum,  pageSize, sourceType,status, createTime,orderSn, orderType, receiverKeyword);
        return CommonResult.success(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public CommonResult selectById(@PathVariable Integer id) {
        OmsOrderVO omsOrderVO = orderService.selectById(id);
        return CommonResult.success(omsOrderVO);
    }

    /**
     * 修改数据
     *
     * @param ids 实体对象
     * @return 修改结果
     */
    @PostMapping("/update/close")
    public CommonResult updateToClose(@RequestParam("ids") List<Integer> ids, String note) {
        orderService.updateToClose(ids, note);
        return CommonResult.success("success");
    }


    @PostMapping("/update/delivery")
    public CommonResult updateDelivery(@RequestBody List<Map<String,Object>>  deliveryParamList) {
        orderService.updateDelivery(deliveryParamList);
        return CommonResult.success("success");
    }

    @PostMapping("/update/moneyInfo")
    public CommonResult updateMoneyInfo(@RequestBody Map<String,Object> moneyInfoParamList) {
        orderService.updateMoneyInfo(moneyInfoParamList);
        return CommonResult.success("success");
    }
    @PostMapping("/update/receiverInfo")
    public CommonResult updateReceiverInfo(@RequestBody Map<String,Object> receiverInfoParamList) {
        orderService.updateReceiverInfo(receiverInfoParamList);
        return CommonResult.success("success");
    }

    @PostMapping("/update/note")
    public CommonResult updateNote(Integer id,Integer status,String note) {
        orderService.updateNote(id,status,note);
        return CommonResult.success("success");
    }

    /**
     * 批量删除订单
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Integer> ids) {
        orderService.delete(ids);
        return CommonResult.success("success");
    }
}

